import { Modal, ModalFuncProps } from 'antd'

export class MessageBox {
  static info (config: ModalFuncProps) {
    return new Promise((resolve, reject) => {
      Modal.info({
        ...config,
        onOk: () => {
          config.onOk && config.onOk()
          resolve(true)
        },
        onCancel: () => {
          config.onCancel && config.onCancel()
          reject(false)
        }
      })
    })
  }
  static success (config: ModalFuncProps) {
    return new Promise((resolve, reject) => {
      Modal.success({
        ...config,
        onOk: () => {
          config.onOk && config.onOk()
          resolve(true)
        },
        onCancel: () => {
          config.onCancel && config.onCancel()
          reject(false)
        }
      })
    })
  }
  static warning (config: ModalFuncProps) {
    return new Promise((resolve, reject) => {
      Modal.warning({
        ...config,
        onOk: () => {
          config.onOk && config.onOk()
          resolve(true)
        },
        onCancel: () => {
          config.onCancel && config.onCancel()
          reject(false)
        }
      })
    })
  }
  static error (config: ModalFuncProps) {
    return new Promise((resolve, reject) => {
      Modal.error({
        ...config,
        onOk: () => {
          config.onOk && config.onOk()
          resolve(true)
        },
        onCancel: () => {
          config.onCancel && config.onCancel()
          reject(false)
        }
      })
    })
  }
  static confirm (config: ModalFuncProps) {
    return new Promise((resolve, reject) => {
      Modal.confirm({
        ...config,
        onOk: () => {
          config.onOk && config.onOk()
          resolve(true)
        },
        onCancel: () => {
          config.onCancel && config.onCancel()
          reject(false)
        }
      })
    })
  }
}
